require('../../../../../resources/assets/js/bootstrap');

const app = new Vue({
    el: '#app',
    data: {
        loginForm: {
            username: '',
            password: '',
            sms_code:'',
            timer_text:'发送验证码'
        },
        show_timer:false,
        time:10
    },
    methods: {
        sendSMS:function(){
            this.countDown();
            axios.post('/admin/send_code',this.loginForm).then(res=>{
                if(res.data.code === 0){
                    //window.location.href = redirect_url;
                } else {
                    this.$message(res.data.msg);
                }
            }).catch(err=>{
                this.show_timer = true;
            });
        },
        submitForm:function() {
            axios.post('/admin/login', this.loginForm).then(res => {
                if(res.data.code === 0){
                    window.location.href = redirect_url;
                } else {
                    this.$message(res.data.msg);
                }
            }).catch(err => {

            });
        },
        countDown:function(){
            let that = this;
            this.show_timer = true;
            let interval = window.setInterval(function(){
                let el = document.getElementById('el_timer');
                el.innerText = '('+ that.time + ')' + '秒后重新发送';
                --that.time;
                console.log(that.time);
                if(that.time<0){
                    that.show_timer = false;
                    that.time = 60;
                    el.innerText = '发送验证码';
                    window.clearInterval(interval);
                }
            },1000);
        }
    }
});
